class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :topics
  has_many :articles

  has_many :topic_pay_logs
  has_many :paid_topics,
           through: :topic_pay_logs,
           source: :topic

  has_many :follow_topic_ships
  has_many :follow_topics,
           through: :follow_topic_ships,
           source: :topic

  has_many :followers,
           through: :FollowUserShip,
           foreign_key: 'befollower_id'
  has_many :befollowers,
           through: :FollowUserShip,
           foreign_key: 'follower_id'



  attr_readonly :email

  validates :name,
            uniqueness: true,
            presence: { :message => '名字不能为空' },
            :length => {:minimum => 2, :maximum => 20, :message => "最少2个字，最多20个字"}



end
